package com.huawei.fakedouyin.util

import android.content.Context
import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.text.TextUtils
import android.widget.Toast
import androidx.core.content.ContextCompat
import com.huawei.fakedouyin.base.BaseApplication
import com.huawei.fakedouyin.config.launchMain
import kotlinx.coroutines.GlobalScope
import org.json.JSONObject

/**
 * @author: WangYT
 * @date: {2023/2/3 13:14}
 * @remake:
 */
fun printJson(msg: String): String {
    try {
        return JSONObject(msg).toString(4)
    } catch (e: Exception) {
    }
    return msg
}

fun isStringEmpty(str: String?): Boolean {
    return TextUtils.isEmpty(str)
}

fun isListEmpty(list: List<*>?): Boolean {
    return list == null || list.isEmpty()
}

fun isStringEqual(str1: String?, str2: String?): Boolean {
    return str1 == str2
}


fun getColor(color: Int, context: Context = BaseApplication.Instance): Int {
    return ContextCompat.getColor(context, color)
}

fun getDrawable(drawRes: Int, context: Context = BaseApplication.Instance): Drawable? {
    return ContextCompat.getDrawable(context, drawRes)
}

fun loadActivity(clazz: Class<*>, bundle: Bundle? = null) {
    val activity = ActivityUtil.Instance.getCurrentActivity()
    val intent = Intent(activity, clazz)
    if (bundle != null) {
        intent.putExtras(bundle)
    }
    activity?.startActivity(intent)
}

fun showToast(str: CharSequence?) {
    GlobalScope.launchMain {
        Toast.makeText(BaseApplication.Instance, str, Toast.LENGTH_SHORT).show()
    }
}
